/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package Controller;

import Model.GpsVehiculo;
import java.util.ArrayList;
import javax.swing.JPanel;
import sistemadeer.SistemaDEER;
import sistemadeer.SistemaDEER.Rejilla;

/**
 *
 * @author Rossy
 */
public class ControlarVehiculo implements Runnable{
    private SistemaDEER principal;
    private JPanel mapa;
    Rejilla rejilla;
    ArrayList<GpsVehiculo>gpsList=new ArrayList<GpsVehiculo>();
    long tiempo=0;
    Thread hilo=new Thread();
    int seg=0;
    
    public ControlarVehiculo(SistemaDEER principal,JPanel mapa,Rejilla rejilla,ArrayList<GpsVehiculo>gpsList){
        this.principal=principal;
        this.mapa=mapa;
        this.gpsList=gpsList;
        this.rejilla=rejilla;
    }
 
    public void run() {
        int x, y, tiempo, velocidad;
        while (true) {
//            if (seg == 30) {
//                seg = 0;
//            }
//            seg++;
            
            for (int i = 0; i < gpsList.size(); i++) {
                x = gpsList.get(i).getPosX();
                y = gpsList.get(i).getPosY();
                tiempo = gpsList.get(i).getTiempo();
                velocidad = gpsList.get(i).getVelocidad();
//                if (seg == 30) {

                if (seg == 30) {
                  seg = 0;
            }
            seg++;

                
//                if (seg == tiempo) {   
             if(seg==30){
                    gpsList.get(i);
//                    seg=0;
                    this.principal.getRejilla().paintVehiculo(x+5, y+5);
                }
            }
            
            try {
                System.out.println("seg "+seg);
                Thread.sleep(1000); // para durar un segundo
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    
    }
   
}
